package com.fdb.efp.nls.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.PubConstant;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.cus.service.facade.CusHandoverLogService;
import com.fdb.efp.cus.service.vo.CusHandoverLogListVO;
import com.fdb.efp.cus.service.vo.CusHandoverLogVO;
import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class CusHandoverLogController extends AbstractController  {
	
	@Autowired
	@Qualifier("cusHandoverLogService")
	private CusHandoverLogService cusHandoverLogService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;
	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/cus/handover/logs", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<CusHandoverLogVO>> queryCusHandoverLogAll(
			@RequestBody CusHandoverLogVO vo) {		
		
		if(vo.getInputDates()!=null && vo.getInputDates().length == 2) {
			vo.setInputStartDate(vo.getInputDates()[0]);
			vo.setInputEndDate(vo.getInputDates()[1]);
		}
		// 根据用户角色获取用户权限方案
		List<CusHandoverLogVO> outputVo = null;
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);

		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = cusHandoverLogService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = cusHandoverLogService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = cusHandoverLogService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = cusHandoverLogService.queryAllOwner(vo);
			break;
		}
		return getResponseData(outputVo);
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/cus/handover/log/{serno}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<CusHandoverLogVO> queryByPk(@PathVariable("serno") String serno) {		
		CusHandoverLogVO inVo = new CusHandoverLogVO();
				inVo.setSerno(serno);
		CusHandoverLogVO outputVo = cusHandoverLogService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param cusHandoverLog
	 * @return
	 */
	@RequestMapping(value="/cus/handover/log", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody CusHandoverLogVO inCusHandoverLogVo) {		
		int outputVo = cusHandoverLogService.deleteByPk(inCusHandoverLogVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inCusHandoverLogVo
	 * @return
	 */
	@RequestMapping(value="/cus/handover/log", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody CusHandoverLogVO inCusHandoverLogVo) {		
		int outputVo = cusHandoverLogService.updateByPk(inCusHandoverLogVo);
		return getResponseData(outputVo);
		
	}
	@RequestMapping(value="/cus/handover/lsts/hist", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<CusHandoverLogVO>> queryCusHandoverLstByHosAll(
			@RequestBody CusHandoverLogVO cusHandoverLog) {	
		List<CusHandoverLogVO> outputVo = cusHandoverLogService.queryLstBySerno(cusHandoverLog);
		return getResponseData(outputVo);
	}
	/**
	 * 新增数据
	 * @param inCusHandoverLogVo
	 * @return
	 */
	@RequestMapping(value="/cus/handover/log", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertCusHandoverLog(@RequestBody CusHandoverLogVO inCusHandoverLogVo) {
		int outputVo = cusHandoverLogService.insertCusHandoverLog(inCusHandoverLogVo);
		return getResponseData(outputVo);
		
	}
	
	@RequestMapping(value="/cus/handover/log/more", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertMore( 
			@RequestBody CusHandoverLogListVO cusHandoverLogListVO){
		@SuppressWarnings("unused")
		List<CusHandoverLogVO> list = cusHandoverLogListVO.getList();
		int total = 0;
		return getResponseData(total);
	}
	
}
